<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9"/>
    <!--The viewport meta tag is used to improve the presentation and behavior
    of the samples on iOS devices-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>proj4 for china coordinate systems</title>
    <link rel="shortcut icon"
          type="image/png" href="http://www.patrick-wied.at/img/favicon.png"/>
    <link rel="stylesheet" href="https://js.arcgis.com/3.24/esri/css/esri.css">
    <style>
        body, html {
            margin: 0;
            padding: 0;
            width: 99.9%;
            height: 99.9%;
            font-family: Arial;
        }

        #map {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            border: 0px dashed black;
            background-color: rgb(0, 38, 48);
        }

    </style>
</head>
<body>
<div id="map">

</div>
</body>
<script src="proj4-src.js"></script>
<script src="https://js.arcgis.com/3.24/"></script>
<script type="text/javascript">
    var map;
    require([
        "esri/map",
        "dojo/on",
        "dojo/dom",
        "esri/layers/ArcGISTiledMapServiceLayer",
        "esri/tasks/query",
        "esri/tasks/QueryTask",
        "esri/geometry/screenUtils",
        "esri/geometry/Extent",
        "esri/geometry/Point",
        "dojo/domReady!"
    ], function (
        Map,
        on,
        dom,
        ArcGISTiledMapServiceLayer,
        Query,
        QueryTask,
        screenUtils,
        Extent,
        Point
    ) {
        // Variables
        var valueField = 'Focal'
        // get the features within the current extent from the feature layer
        function getFeatures() {
            var q = new Query();
            var url = 'http://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Earthquakes_Since_1970/FeatureServer/0'
            var queryTask = new QueryTask(url);
            q.geometry = map.extent;
            q.where = "1=1";
            q.outFields = [valueField ]
            q.orderByFields = [valueField ];
            q.returnGeometry = true
            q.geometryPrecision = 10;
            q.outSpatialReference = map.spatialReference;
            queryTask.execute(q, function (re) {
                console.log(re.features.length)
                if (re.features.length) {
                    //console.time('end')
                    //transform(re.features);
                    //console.timeEnd('end')
                }
            });
        }
        function transform(features) {
            for(let i=0;i<features.length;i++){
                let geometry=features[i].geometry;
                let srcPoint=[geometry.x,geometry.y];
                console.log('EPSG:3857->'+srcPoint);
                let result = proj4("EPSG:"+geometry.spatialReference.latestWkid, "EPSG:4326", srcPoint);
                console.log("EPSG:4326->"+result);
            }
        }
        var mapExtent = new Extent({
            xmax:22189975.059293926,
            xmin: -15302081.56646192,
            ymax: 8961447.604325403,
            ymin: -9569334.036901515,
            spatialReference: {wkid: 102100}
        })

        map = new Map("map", {
            basemap: "gray",
            extent: mapExtent,
            sliderStyle: "small",
            logo: false
        });

        map.resize();
        
        //getFeatures()
        getFeatures();
});
      

</script>

<script src="crs.js"></script>
<script>

    // getPrjZoneEpsg("Beijing_1954_",3,25,45,2401);
    // getPrjCMEpsg("Beijing_1954_",3,75,135,2422);
    // getPrjZoneEpsg("Beijing_1954_",6,13,23,21413);
    // getPrjCMEpsg("Beijing_1954_",6,75,135,21473);
    //
    // getPrjZoneEpsg("Xian_1980_",3,25,45,2349);
    // getPrjCMEpsg("Xian_1980_",3,75,135,2370);
    // getPrjZoneEpsg("Xian_1980_",6,13,23,2327);
    // getPrjCMEpsg("Xian_1980_",6,75,135,2338);
    //
    // getPrjZoneEpsg("CGCS_2000_",3,25,45,4513);
    // getPrjCMEpsg("CGCS_2000_",3,75,135,4534);
    // getPrjZoneEpsg("CGCS_2000_",6,13,23,4491);
    // getPrjCMEpsg("CGCS_2000_",6,75,135,4502);

    function getPrjZoneEpsg(prename,degree,startzone,endzone,startepsg) {
        let PRJ_EPSG={};
        for(let i=startzone;i<=endzone;i++){
            let name=prename+degree+"_Degree_GK_Zone_"+i;
            PRJ_EPSG[name]=startepsg;
            startepsg++;
        }
        console.log(prename+degree+"_Degree_GK_Zone")
        console.log(PRJ_EPSG)
        return PRJ_EPSG;
    }
    function getPrjCMEpsg(prename,degree,starCM,endCM,startepsg) {
        let PRJ_EPSG={};
        for(let i=starCM;i<=endCM;i+=degree){
            let name=prename+degree+"_Degree_GK_CM_"+i+"E";
            PRJ_EPSG[name]=startepsg;
            startepsg++;
        }
        console.log(prename+degree+"Degree_GK_CM")
        console.log(PRJ_EPSG)
        return PRJ_EPSG;
    }
</script>
</html>